<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Returns a character set object</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mysqli.field-count.html">« mysqli::$field_count</a></li>
      <li style="float: right;"><a href="mysqli.get-client-info.html">mysqli::$client_info »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.mysqli.html">MySQLi</a></li>
    <li>Returns a character set object</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mysqli.get-charset" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqli::get_charset</h1>
  <h1 class="refname">mysqli_get_charset</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.1.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">mysqli::get_charset</span> -- <span class="refname">mysqli_get_charset</span> &mdash; <span class="dc-title">Returns a character set object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqli.get-charset-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>mysqli::get_charset</strong></span>(): <span class="type"><span class="type">?</span><span class="type">object</span></span></div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>mysqli_get_charset</strong></span>(<span class="methodparam"><span class="type"><a href="class.mysqli.html" class="type mysqli">mysqli</a></span> <code class="parameter">$mysql</code></span>): <span class="type"><span class="type">?</span><span class="type">object</span></span></div>


  <p class="para rdfs-comment">
   Returns a character set object providing several properties 
   of the current active character set.
  </p> 

 </div>


 <div class="refsect1 parameters" id="refsect1-mysqli.get-charset-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    <dt>

<code class="parameter">mysql</code></dt>
<dd>
<p class="para">仅以过程化样式：由<span class="function"><a href="function.mysqli-connect.html" class="function">mysqli_connect()</a></span> 或 <span class="function"><a href="mysqli.init.html" class="function">mysqli_init()</a></span>
返回的 <span class="classname"><a href="class.mysqli.html" class="classname">mysqli</a></span> 对象。</p></dd>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysqli.get-charset-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   The function returns a character set object with the following properties:
   <dl>
    
     <dt>
<code class="parameter">charset</code></dt>

     <dd>
<p class="para">Character set name</p></dd>

    
    
     <dt>
<code class="parameter">collation</code></dt>

     <dd>
<p class="para">Collation name</p></dd>

    
    
     <dt>
<code class="parameter">dir</code></dt>

     <dd>
<p class="para">Directory the charset description was fetched from (?) or &quot;&quot; for built-in character sets</p></dd>

    
    
     <dt>
<code class="parameter">min_length</code></dt>

     <dd>
<p class="para">Minimum character length in bytes</p></dd>

    
    
     <dt>
<code class="parameter">max_length</code></dt>

     <dd>
<p class="para">Maximum character length in bytes</p></dd>

    
    
     <dt>
<code class="parameter">number</code></dt>

     <dd>
<p class="para">Internal character set number</p></dd>

    
    
     <dt>
<code class="parameter">state</code></dt>

     <dd>
<p class="para">Character set status (?)</p></dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mysqli.get-charset-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1456">
   <p><strong>示例 #1 <span class="methodname"><strong>mysqli::get_charset()</strong></span> example</strong></p>
   <div class="example-contents"><p>面向对象风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_init</span><span style="color: #007700">();<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">real_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,</span><span style="color: #DD0000">""</span><span style="color: #007700">,</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">get_charset</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>过程化风格</p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$db&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_init</span><span style="color: #007700">();<br />&nbsp;&nbsp;</span><span style="color: #0000BB">mysqli_real_connect</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,</span><span style="color: #DD0000">""</span><span style="color: #007700">,</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br />&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">mysqli_get_charset</span><span style="color: #007700">(</span><span style="color: #0000BB">$db</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程会输出：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
object(stdClass)#2 (7) {
  [&quot;charset&quot;]=&gt;
  string(6) &quot;latin1&quot;
  [&quot;collation&quot;]=&gt;
  string(17) &quot;latin1_swedish_ci&quot;
  [&quot;dir&quot;]=&gt;
  string(0) &quot;&quot;
  [&quot;min_length&quot;]=&gt;
  int(1)
  [&quot;max_length&quot;]=&gt;
  int(1)
  [&quot;number&quot;]=&gt;
  int(8)
  [&quot;state&quot;]=&gt;
  int(801)
}
</pre></div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqli.get-charset-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysqli.character-set-name.html" class="function" rel="rdfs-seeAlso">mysqli_character_set_name()</a> - 返回当前数据库连接的默认字符编码</span></li>
    <li class="member"><span class="function"><a href="mysqli.set-charset.html" class="function" rel="rdfs-seeAlso">mysqli_set_charset()</a> - 设置默认字符编码</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>